package com.yungu.swift.admin.route.system;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.system.sys.model.dto.SysFenceDto;
import com.yungu.swift.system.sys.model.param.AdminFenceParam;
import com.yungu.swift.system.sys.model.vo.SysFenceVo;
import com.yungu.swift.system.sys.service.SysFenceService;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 围栏功能
 */
@RestController
@RequestMapping("/admin/v1/system/fence")
@Api(value = "【系统服务-围栏功能】", tags = "围栏功能设置")
public class FenceAdmin {

    @Reference
    private SysFenceService sysFenceService;

    @RequestMapping(value = "/queryList", method = RequestMethod.POST)
    @ApiOperation(value = "围栏查询", httpMethod = "POST")
    public ResponseData<PageVo<SysFenceVo>> queryList(@RequestBody AdminFenceParam adminFenceParam) {
        return sysFenceService.queryPageVo(adminFenceParam);
    }

    @RequestMapping(value = "/saveFence", method = RequestMethod.POST)
    @ApiOperation(value = "保存围栏", httpMethod = "POST")
    public ResponseData<Boolean> addFence(@RequestBody AdminFenceParam adminFenceParam) {
        //新增
        if(StringUtils.isEmpty(adminFenceParam.getUuid())){
            return sysFenceService.addFence(adminFenceParam);
        }else{
            //编辑
            SysFenceDto sysFenceDto = new SysFenceDto();
            BeanUtils.copyProperties(adminFenceParam,sysFenceDto);
            sysFenceDto.setUpdateBy(adminFenceParam.getUserUuid());
            return sysFenceService.edit(sysFenceDto);
        }
    }

    @RequestMapping(value = "/delFence", method = RequestMethod.POST)
    @ApiOperation(value = "删除围栏", httpMethod = "POST")
    public ResponseData<Boolean> delFence(@RequestBody AdminFenceParam adminFenceParam) {
        SysFenceDto sysFenceDto = new SysFenceDto();
        sysFenceDto.setUuid(adminFenceParam.getUuid());
        sysFenceDto.setFenceGid(adminFenceParam.getFenceGid());
        return sysFenceService.del(sysFenceDto);
    }
}
